
/**
 * SigmaCMS - Content Management System
 *
 * Copyright (C) 2008 Pavol Biely
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    SigmaCMS
 * @author     Pavol Biely <pavolbiely@gmail.com>
 * @copyright  2008 Pavol Biely
 * @license    http://www.gnu.org/licenses/gpl.txt   GNU General Public License
 * @link       http://pabi3.com/
 * @since      0.1.0
 */

/*** Show <textarea> of template ***/
function addTemplateContent(id) {
	document.getElementById(id).style.display = 'block';
	document.getElementById(id + '-link').style.display = 'none';
}

/*** Add or remove rows in <textarea> ***/
function addTemplateRow(id,num) {
	var textarea = document.getElementById(id);
	if (textarea.rows+num > 4 && textarea.rows+num < 40) {
		document.getElementById(id).setAttribute('rows',textarea.rows+num);
	}
}

/*** Add value to <textarea> ***/
function addValue(id,value) {
    var element = document.getElementById(id);

    if(document.selection) {
        element.focus();
        var select = document.selection.createRange();
        select.text = value;
    } else if (element.selectionStart || element.selectionStart == '0') {
        var startPos = element.selectionStart;
        var endPos  = element.selectionEnd;
        element.value = element.value.substring(0, startPos) + value + element.value.substring(endPos, element.value.length);
    } else {
        element.value += value;
    }
}

/*** Selecting <select> ***/
function selectAll(id,check) {
	var select = document.getElementById(id);

	for (var i = 0; i < select.length; i++) {
		select.options[i].selected = check;
	}
	
	return true;
}

function isSelectedAll(id,msg) {
	var selected = 0;
	var select = document.getElementById(id);

	for (var i = 0; i < select.length; i++) {
		if (select.options[i].selected) {
			selected = true;
			break;
		}
	}

	if (selected == 0) {
		alert(msg);
		return false;
	}

	return true;
}

/*** Check log in form ***/
function checkLogIn() {
	var check = true;
	if (document.getElementById('username').value == '') {
		check = false;
	}
	if (document.getElementById('password').value == '') {
		check = false;
	}
	return check;
}